﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using xIx.Web.AccessControl;

public partial class UserControls_LoginCtl : xIx.Web.UI.ControlBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex= (Page.User != null && Page.User.Identity.IsAuthenticated) ? 0 : 1;
    }

    protected void LogoffButton_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        //Response.Redirect(FormsAuthentication.LoginUrl);
        Response.Redirect(Request.RawUrl);
    }

    protected void LoginButton_Click(object sender, EventArgs e)
    {
        Page.Validate("Login");
        if (!Page.IsValid) return;

        string u = UserName.Text;
        string p = Password.Text;

        BizAccountInfo ai = BizPrincipal.TryLogin(u, p);
        if (null == ai){Alert("登录错误。"); return;}

        BizPrincipal.SetAuthCookie(ai,true);
        //Response.Redirect(Request.RawUrl);
    }

}
